﻿using AutoCreatTables.Business;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace AutoCreatTables.UI
{
    public partial class CreatTablesForm : Form
    {
        /// <summary>
        /// 显示页面信息委托
        /// </summary>
        private Action<string> showMsgHandler = null;

        /// <summary>
        /// 
        /// </summary>
        public CreatTablesForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form1_Load(object sender, EventArgs e)
        {
            // 处理底层到页面显示的事件
            ShowBusiness.ShowMsgEvent += new Action<string>(this.ShowMessge_ShowMsg);
            // 页面显示委托
            this.showMsgHandler = new Action<string>(this.PrintMsg);

            AutoAnalyseAndCreatTables autoAnalyseAndCreatTables = new AutoAnalyseAndCreatTables();
            autoAnalyseAndCreatTables.StartAnalyseAndCreatTables();
        }

        /// <summary>
        /// 显示需要显示的页面提示信息的事件实现
        /// </summary>
        /// <param name="msg">页面提示信息</param>
        private void ShowMessge_ShowMsg(string msg)
        {
            this.Invoke(this.showMsgHandler, msg);
        }

        /// <summary>
        /// 具体页面显示
        /// </summary>
        /// <param name="msg">页面显示内容</param>
        private void PrintMsg(string msg)
        {
            msg = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + ":" + msg + Environment.NewLine;
            if (this.ShowtextBox.TextLength > 50000)
            {
                this.ShowtextBox.Text = msg;
            }
            else
            {
                this.ShowtextBox.AppendText(msg);
            }
        }
    }
}
